/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.ispc.foundation.rutils;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.concurrent.TimeUnit;

/**
 * Created by Peter.Li on 2015/10/28.
 */
public interface RConfiguration extends Remote {
    /**
     * Get a configuration for an Rserve instance.
     *
     * @return A populated configuration that represents an Rserve instance.
     * @throws RemoteException if the configuration cannot be accessed
     */
    RConfigurationItem borrowConfigurationItem() throws RemoteException;

    /**
     * Get a configuration for an Rserve instance. If no items are available at the moment,
     * this method will wait up to the specified wait time for a configuration to become available.
     *
     * @param timeout how long to wait before giving up, in units of <tt>unit</tt>
     * @param unit    a <tt>TimeUnit</tt> determining how to interpret the <tt>timeout</tt> parameter
     * @return A valid object or null if no connection was available within the timeout period
     * @throws RemoteException if the configuration cannot be accessed
     */
    RConfigurationItem borrowConfigurationItem(long timeout, TimeUnit unit) throws RemoteException;

    /**
     * Return a configuration for an Rserve instance to the available list.
     *
     * @param item A populated configuration that represents an Rserve instance.
     * @throws RemoteException if the configuration cannot be stored
     */
    void returnConfigurationItem(RConfigurationItem item) throws RemoteException;
}
